
#ifndef __RSA_DECRYPT_H
#define __RSA_DECRYPT_H

#include "CryptoPipeBlock.h"
#include "../aprtools/APRBucketBrigade.h"
#include <openssl/rsa.h>
#include "RSAPrivateKey.h"

/** Class encapsulating an interface to decryption with an RSA private
 * key. */
class RSADecrypt : public CryptoPipeBlock
{
   public:
      RSADecrypt(const RSAPrivateKey &rsaprvkey);
      RSADecrypt(APRBucketBrigade &iinput, APRBucketBrigade &ioutput, const RSAPrivateKey &rsaprvkey);
      ~RSADecrypt();
      // Decrypt data block and return plaintext data
      char *processDataBlock(const char *codedblock, apr_size_t codedsize, apr_size_t *plainsize);
      // Begin decryption of the data pipe
      int processPipeBegin();
      // Step through the decryption of the data pipe
      int processPipeStep();
      // Step through the data, recording data movement
      int processPipeStep(int *movementin, int *movementout);
      // End decryption of the data pipe
      int processPipeEnd();
      /** Was the process secure? */
      int processWasSecure() { return 1; }
   private:
      /** A copy of the RSA private key. */
      RSA *key;
      /** The input bucket brigade. As this is pointer to the outside,
       * it is not deleted in the destructor. */
      APRBucketBrigade *input;
      /** The output bucket brigade. As this is pointer to the
       * outside, it is not deleted in the destructor. */
      APRBucketBrigade *output;
      /** The previously encrypted block for CBC. */
      char *previous_block;
};

#endif
